package com.oracle.application.controller;

import com.oracle.application.config.PayConfig;
import com.oracle.application.entity.vo.PayAsyncVo;
import com.oracle.application.entity.vo.PayVo;
import com.oracle.application.entity.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class PayController {
    @Autowired
    private PayConfig payConfig;

    @GetMapping("/pay")
    public  String pay(String orderSn,String totalPrice,Integer orderId){
        PayVo payVo=new PayVo();
        payVo.setTotal_amount(totalPrice);
        payVo.setOut_trade_no(orderSn);
        payVo.setSubject("测试支付");
        String page=payConfig.doPay(payVo,orderId);
        return page;
    }

    @PostMapping("/pay/notify_url")
    public  String notify_url(PayAsyncVo payAsyncVo){
        System.out.println("异步验签contro=====================");
        if (this.payConfig.verifySignature(payAsyncVo)){
            return  "success";
        }
        return  "failure";
    }
    @GetMapping("/pay/return_url")
    public R return_url(PayAsyncVo payAsyncVo){
        if (this.payConfig.returnVerifySignature(payAsyncVo)){
            return new R(200,"success","支付完成,等到发货");
        }
    return new R(201,"fail","支付出现问题,请核实后再次支付");
}

}
